package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallGoodsAttributeMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsAttribute;
import org.linlinjava.litemall.db.domain.LitemallGoodsAttributeExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class LitemallAttributeService {

    @Resource
    LitemallGoodsAttributeMapper attributeMapper;

    public List<LitemallGoodsAttribute> queryByGid(Integer gid){
        LitemallGoodsAttributeExample example = new LitemallGoodsAttributeExample();
        example.or().andGoodsIdEqualTo(gid).andDeletedEqualTo(false);
        return attributeMapper.selectByExample(example);
    }

    public int deleteByGid(Integer id){
        return attributeMapper.updateById(id);
    }

    public int add(LitemallGoodsAttribute attribute){
        attribute.setAddTime(new Date());
        attribute.setUpdateTime(new Date());
        return attributeMapper.insert(attribute);
    }

    public int update(LitemallGoodsAttribute attribute){
        attribute.setAddTime(new Date());
        attribute.setUpdateTime(new Date());
        return attributeMapper.updateByPrimaryKeySelective(attribute);
    }

}
